
console.log('Demo Run JS.[init]..');

// 向页面注入JS
function injectCustomJs(jsPath)
{
    jsPath = jsPath || 'js/inject.js';
    var temp = document.createElement('script');
    temp.setAttribute('type', 'text/javascript');
    // 获得的地址类似：chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
    temp.src = chrome.extension.getURL(jsPath);
    temp.onload = function()
    {
        // 放在页面不好看，执行完后移除掉
        this.parentNode.removeChild(this);
    };
    document.head.appendChild(temp);
}

 if (window.location.pathname == '/LMS/coursePlayer/player.do') {
	window.addEventListener("message", function(event){
		console.log('Init.js Message', event);
		if(event.data.type == 'notify'){
			console.log(event.data);
			var title = event.data.title || '通知标题';
			var message = event.data.message || '通知消息内容';
			chrome.runtime.sendMessage({type:"notify",title:title,message:message}, function(response) {
				console.log('收到来自后台的回复：' + response);
			});
		}
	}, true);
	injectCustomJs('js/list.js');
}

if (window.location.pathname == '/coursePlayer/player.do') {
	injectCustomJs('js/video.js');
}


